<template>
    <d2-container>
        <template slot="header">
            <el-row>
                <!-- 搜索 -->
                <el-col align="left" :span="18">
                    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList">
                        <el-form-item class="no-m-bottom">
                            <el-input v-model="dataForm.title" placeholder="订单编号" clearable />
                        </el-form-item>
                        <el-form-item class="no-m-bottom">
                            <el-button @click="getDataList">查询</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
                <!-- 新增 -->
                <el-col align="right" :span="6">
                    <el-button type="primary" @click="addOrUpdateHandle">新增</el-button>
                </el-col>
            </el-row>
        </template>
        <!-- 列表数据 -->
        <el-table v-loading="dataListLoading" :data="dataList" border style="width: 100%">
            <!-- 属性 -->
            <el-table-column type="index" width="50" align="center"></el-table-column>
            <el-table-column prop="title" label="标题" align="center"></el-table-column>
            <el-table-column prop="image" label="图片" align="center">
                <template slot-scope="scope">
                    <el-image style="width: 100px; height: 100px" :src="scope.row.image"></el-image>
                </template>
            </el-table-column>
            <el-table-column prop="price" label="价格" align="center"></el-table-column>
            <el-table-column prop="status" label="状态" align="center">
                <template slot-scope="scope">
                    {{ scope.row.status | filterProductStatus }}
                </template>
            </el-table-column>
            <!-- 操作 -->
            <el-table-column label="操作" fixed="right" width="150" align="center">
                <template slot-scope="scope">
                    <el-button type="primary" @click="addOrUpdateHandle(scope.row.id)">
                        编辑
                    </el-button>
                    <el-button type="danger" @click="deleteHandle(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <template slot="footer">
            <!-- 分页 -->
            <el-pagination
                align="right"
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="limit"
                :total="total"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="pageSizeChangeHandle"
                @current-change="pageCurrentChangeHandle"
            ></el-pagination>
        </template>
        <!-- 弹窗，新增 / 修改 -->
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" />
    </d2-container>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import mixinFilters from '@/mixins/filters'
import addOrUpdate from './add-or-update'
export default {
    mixins: [mixinViewModule, mixinFilters],
    data() {
        return {
            mixinViewModuleOptions: {
                getDataListURL: '/products/get',
                deleteURL: '/products/del'
            }
        }
    },
    components: {
        addOrUpdate
    }
}
</script>
